<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Menu extends CI_Model {    	
	public function __construct() {
		parent::__construct();
	}
    public function getMenus($options = array()) {    	
    	$options = _default(array('sortBy' => 'mnu_order', 'sortDirection' => 'asc'), $options);
    	$queryFields = array('mnu_id', 'mnu_label', 'mnu_page', 'mnu_parent', 'mnu_route');

    	foreach ($queryFields as $field) {
    		if (isset($options[$field]))
    			$this->db->where(field, $options[$field]);
    	}
    	
    	if (isset($options['limit']) && isset($options['offset']))
    		$this->db->limit($options['limit]'], $options['offset']);
    	else if (isset($options['limit']))
    		$this->db->limit($options['limit]']);
    	
    	if (isset($options['sortBy']))
    		$this->db->order_by($options['sortBy'], $options['sortDirection']);
    	$query = $this->db->get('acs_menu');
    	if ($query->num_rows() == 0)
    		return FALSE;
    	if (isset($options['mnu_id']))
    		return $query->row_array(0);
    	else {
    		return getHierarchy($query->result_array(), 'mnu_id', 'mnu_parent');
    	}
    }
    
    public function updateMenu($options = array()) {
    }
    
    public function insertMenu($options = array()) {
    }
    
    public function deleteMenu($options = array()) {    	
    }
}
